#include "Vector.hh"
#include "common/stl.h"

// Ctor / Dtor
Vector::Vector() : _x(0), _y(0), _z(0)
{
}

Vector::Vector(float x, float y, float z) : _x(x), _y(y), _z(z)
{
}

Vector::~Vector()
{
	#ifdef DEBUG
		std::cout << "Vector: rmed " << _x << _y << _z << std::endl;
	#endif
}
// end Ctor / Dtor


// getters / setters
float Vector::getX() const
{
    return ((float const) _x);
}

float Vector::getY() const
{
    return ((float const) _y);
}

float Vector::getZ() const
{
    return ((float const) _z);
}


float Vector::x() const
{
    return ((float const) _x);
}

float Vector::y() const
{
    return ((float const) _y);
}

float Vector::z() const
{
    return ((float const) _z);
}



Vector Vector::operator^ (const Vector &v)
{
    float x = _y * v._z - _z * v._y;
    float y = _z * v._x - _x * v._z;
    float z = _x * v._y - _y * v._x;

    return (Vector(x, y, z));
}

Vector Vector::operator- () const
{
    return (Vector (-_x, -_y, -_z));
}


Vector Vector::operator- (const Vector &v)
{
    return (Vector(_x - v._x, _y - v._y, _z - v._z));
}


void Vector::normalize()
{
    float norme = sqrt(_x*_x + _y*_y + _z*_z);

    #ifdef DEBUG
	if (norme > -FLT_EPSILON && norme < FLT_EPSILON) // division by 0
	{
	  std::cerr << "Vector::normalize: Division by 0" << std::endl;
	  return;
	}
    #endif

    _x /= norme;
    _y /= norme;
    _z /= norme;
}


#ifdef DEBUG
    void Vector::print()
    {
        std::cout << _x << " " << _y << " " << _z << std::endl;
    }
#endif
